home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snpd0492.zip / STPTOK.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  944b  |  32 lines

  1. /*
  2. **  stptok() -- public domain by Raymond Gardner
  3. **
  4. **   You pass this function a string to parse, a buffer to receive the
  5. **   "token" that gets scanned, the length of the buffer, and a string of
  6. **   "break" characters that stop the scan.  It will copy the string into
  7. **   the buffer up to any of the break characters, or until the buffer is
  8. **   full, and will always leave the buffer null-terminated.  It will
  9. **   return a pointer to the character that stopped the scan.
  10. */
  11.  
  12. char *stptok(char *s, char *tok, size_t toklen, char *brk)
  13. {
  14.       char *lim, *b;
  15.  
  16.       lim = tok + toklen - 1;
  17.       while ( *s && tok < lim )
  18.       {
  19.             for ( b = brk; *b; b++ )
  20.             {
  21.                   if ( *s == *b )
  22.                   {
  23.                         *tok = 0;
  24.                         return s;
  25.                   }
  26.             }
  27.             *tok++ = *s++;
  28.       }
  29.       *tok = 0;
  30.       return s;
  31. }
  32.